using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;
namespace Lifter.Gui.Monitor.Controls
{
	[Designer("System.Windows.Forms.Design.ParentControlDesigner,System.Design", typeof(IDesigner))]
	public class ControlBase : UserControl
	{
		private Padding _borderThick;
		private Color _borderColor;
		private Color _backColor;
		private Timer _timer;
		private int _blinkInterval;
		private int _blinkTick;
		private IContainer components = null;
		protected Panel panelBack;
		protected Panel panelContent;
		public new event EventDelegate Click;
		public event EventDelegate ControlClicked
		{
			add
			{
				this.Click += value;
			}
			remove
			{
				this.Click -= value;
			}
		}
		public int BlinkInterval
		{
			get
			{
				return this._blinkInterval;
			}
			set
			{
				this._blinkInterval = value;
				this.SetBlink(this._blinkInterval);
			}
		}
		public Padding BorderThick
		{
			get
			{
				return this._borderThick;
			}
			set
			{
				this._borderThick = value;
				this.panelBack.Padding = value;
			}
		}
		public Color BorderColor
		{
			get
			{
				return this._borderColor;
			}
			set
			{
				this._borderColor = value;
				this.panelBack.BackColor = this._borderColor;
			}
		}
		public new Color BackColor
		{
			get
			{
				return base.BackColor;
			}
			set
			{
				base.BackColor = value;
				this.panelContent.BackColor = base.BackColor;
			}
		}
		public new Font Font
		{
			get
			{
				return base.Font;
			}
			set
			{
				base.Font = value;
				this.panelContent.Font = value;
			}
		}
		protected virtual void SetBlink(int interval)
		{
			if (interval <= 0)
			{
				this._blinkInterval = 0;
				this._timer.Enabled = false;
				this.panelBack.BackColor = this._borderColor;
			}
			else
			{
				this._timer.Interval = interval;
				this._timer.Enabled = true;
			}
		}
		public ControlBase()
		{
			this.InitializeComponent();
			this._borderThick = new Padding(1, 1, 1, 1);
			this._borderColor = Color.Black;
			this._backColor = Color.White;
			this._timer = new Timer();
			this._blinkInterval = 0;
			this._blinkTick = 1;
			this.panelBack.Padding = this._borderThick;
			this.panelBack.BackColor = this._borderColor;
			this.panelContent.BackColor = this._backColor;
			this._timer.Tick += new EventHandler(this._timer_Tick);
		}
		protected void _timer_Tick(object sender, EventArgs e)
		{
			if (this._blinkTick % 2 == 0)
			{
				this._blinkTick = 1;
				this.panelBack.BackColor = Color.Transparent;
			}
			else
			{
				this._blinkTick = 2;
				this.panelBack.BackColor = this._borderColor;
			}
			this.TimerTick(this._blinkTick);
		}
		protected virtual void TimerTick(int tick)
		{
		}
		protected virtual void ClickEventRaised(object sender, EventArgs e)
		{
			if (this.Click != null)
			{
				this.Click(sender, e);
			}
		}
		private void panelBack_Click(object sender, EventArgs e)
		{
			this.ClickEventRaised(this, e);
		}
		private void ControlBase_ControlAdded(object sender, ControlEventArgs e)
		{
			e.Control.BringToFront();
		}
		private void panelContent_Click(object sender, EventArgs e)
		{
			this.ClickEventRaised(this, e);
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			this.panelBack = new Panel();
			this.panelContent = new Panel();
			this.panelBack.SuspendLayout();
			base.SuspendLayout();
			this.panelBack.Controls.Add(this.panelContent);
			this.panelBack.Dock = DockStyle.Fill;
			this.panelBack.Location = new Point(0, 0);
			this.panelBack.Margin = new Padding(0);
			this.panelBack.Name = "panelBack";
			this.panelBack.Padding = new Padding(5);
			this.panelBack.Size = new Size(235, 136);
			this.panelBack.TabIndex = 1;
			this.panelContent.Dock = DockStyle.Fill;
			this.panelContent.Font = new Font("Arial", 9.75f, FontStyle.Bold, GraphicsUnit.Point, 129);
			this.panelContent.Location = new Point(5, 5);
			this.panelContent.Name = "panelContent";
			this.panelContent.Size = new Size(225, 126);
			this.panelContent.TabIndex = 0;
			base.AutoScaleDimensions = new SizeF(7f, 12f);
//			base.AutoScaleMode = AutoScaleMode.Font;
			base.Controls.Add(this.panelBack);
			base.Name = "ControlBase";
			base.Size = new Size(235, 136);
			this.panelBack.ResumeLayout(false);
			base.ResumeLayout(false);
		}
	}
}
